//
//  VideoTableViewCell.m
//  ITHome
//
//  Created by lanou3g on 15/7/14.
//  Copyright (c) 2015年 YAX. All rights reserved.
//

#import "VideoTableViewCell.h"
#import "Reachability.h"

@implementation VideoTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:
            reuseIdentifier];

    if (self) {
        
        self.backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, kScreenWidth - 20, 220)];
        self.backImageView.image = [UIImage imageNamed:@"bg_share_large"];
        [self.contentView addSubview:_backImageView];
        
        //背景图片
        self.moviePlayImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _backImageView.width, 180)];
        self.moviePlayImageView.image = [UIImage imageNamed:@"video_recommend_cell_bg"];
        [self.backImageView addSubview:_moviePlayImageView];
        //播放图标
        self.playImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _moviePlayImageView.width, 180)];
        //使图片居中不被拉升
        self.playImageView.contentMode =  UIViewContentModeCenter;
        self.playImageView.image = [UIImage imageNamed:@"video_list_cell_big_icon"];
        [self.moviePlayImageView addSubview:_playImageView];
        
        self.timeImage = [[UIImageView alloc] initWithFrame:CGRectMake(15 , _moviePlayImageView.height + 10, 15, 15)];
        self.timeImage.image = [UIImage imageNamed:@"video_list_cell_time"];
        [self.backImageView addSubview:_timeImage];
        
        self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_timeImage.width + _timeImage.x + 5, _moviePlayImageView.height + 12, 60, 10)];
        self.timeLabel.textColor = [UIColor colorWithRed:140/255.0 green:140/255.0 blue:140/255.0 alpha:1];
        self.timeLabel.font = [UIFont systemFontOfSize:13];
        self.timeLabel.text = @"00:20";
        [self.backImageView addSubview:_timeLabel];
        //播放图
        self.playImage = [[UIImageView alloc] initWithFrame:CGRectMake(_playImageView.width / 2 - 30 , _moviePlayImageView.height + 10, 15, 15)];
        self.playImage.image = [UIImage imageNamed:@"video_list_cell_count"];
        [self.backImageView addSubview:_playImage];
        
        //播放数
        self.playCount = [[UILabel alloc] initWithFrame:CGRectMake(_playImage.width + _playImage.x + 5, _moviePlayImageView.height + 12, 60, 10)];
        self.playCount.textColor = [UIColor colorWithRed:140/255.0 green:140/255.0 blue:140/255.0 alpha:1];
        self.playCount.font = [UIFont systemFontOfSize:13];
        self.playCount.text = @"12345";
        [self.backImageView addSubview:_playCount];
        
        //跟帖图
        self.threadImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_playImageView.width / 2 + 80 , _moviePlayImageView.height + 10, 15, 15)];
        self.threadImageView.image = [UIImage imageNamed:@"comment_support"];
        [self.backImageView addSubview:_threadImageView];
        
        //跟帖数
        self.threadLabel = [[UILabel alloc] initWithFrame:CGRectMake(_threadImageView.width + _threadImageView.x + 5, _moviePlayImageView.height + 13, 60, 10)];
        self.threadLabel.textColor = [UIColor colorWithRed:140/255.0 green:140/255.0 blue:140/255.0 alpha:1];
        self.threadLabel.text = @"20";
        self.threadLabel.font = [UIFont systemFontOfSize:13];
        [self.backImageView addSubview:_threadLabel];
        
        //背景透明图
        self.titleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, _playImageView.x + _playImageView.height - 60, _playImageView.width, 60)];
        self.titleImageView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        [self.playImageView addSubview:self.titleImageView];
        
        //标题
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10,_playImageView.width - 20, 40)];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.titleLabel.numberOfLines = 0;
        self.titleLabel.textColor = [UIColor whiteColor];
        self.titleLabel.font = [UIFont systemFontOfSize:15];
        [self.titleImageView addSubview:_titleLabel];
        
    }
    return self;
}
- (void)cellSetModel:(VideoModel *)model
{
    self.titleLabel.text = model.title;
    self.timeLabel.text = [NSString stringWithFormat:@"%d:%d",(int)model.length / 60 ,(int)model.length % 60];
    self.playCount.text = [NSString stringWithFormat:@"%ld",(long)model.playCount];
    self.threadLabel.text = [NSString stringWithFormat:@"%ld",(long)model.replyCount];
    Reachability *r = [Reachability reachabilityWithHostName:@"www.baidu.com"];
    // 如果没网
    if ([r currentReachabilityStatus] == NotReachable)
    {
        [self.moviePlayImageView sd_setImageWithURL:[NSURL URLWithString:model.cover] placeholderImage:[UIImage imageNamed:@"content_cell_bg"]];
    }
    // 如果3g网
    else if ([r currentReachabilityStatus] == ReachableViaWWAN)
    {
        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isPicture"] == YES)
        {

        }
        else
        {
            [self.moviePlayImageView sd_setImageWithURL:[NSURL URLWithString:model.cover] placeholderImage:[UIImage imageNamed:@"video_recommend_cell_bg"] options:SDWebImageProgressiveDownload];
        }
    }
    // wife
    else if ([r currentReachabilityStatus] == ReachableViaWiFi)
    {
        [self.moviePlayImageView sd_setImageWithURL:[NSURL URLWithString:model.cover] placeholderImage:[UIImage imageNamed:@"video_recommend_cell_bg"] options:SDWebImageProgressiveDownload];
    }
  
}


- (void)awakeFromNib {
    // Initialization code
}


@end
